﻿namespace MES_SystemUI.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class addtables : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.DeviceCategories",
                c => new
                    {
                        DeviceCategoryId = c.Int(nullable: false, identity: true),
                        DeviceCategoryName = c.String(nullable: false, maxLength: 30, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.DeviceCategoryId)
                .Index(t => t.DeviceCategoryName, unique: true);
            
            CreateTable(
                "dbo.DeviceInspections",
                c => new
                    {
                        DeviceInspectionId = c.Int(nullable: false, identity: true),
                        DeviceId = c.Int(nullable: false),
                        CurrentDeviceStatus = c.Int(nullable: false),
                        InspectorId = c.Int(nullable: false),
                        InspectionTime = c.DateTime(nullable: false),
                        Remark = c.String(maxLength: 150, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.DeviceInspectionId);
            
            CreateTable(
                "dbo.DeviceMaintenances",
                c => new
                    {
                        DeviceMaintenanceId = c.Int(nullable: false, identity: true),
                        DeviceId = c.Int(nullable: false),
                        MaintainerId = c.Int(nullable: false),
                        MaintenanceTime = c.DateTime(nullable: false),
                        Remark = c.String(maxLength: 150, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.DeviceMaintenanceId);
            
            CreateTable(
                "dbo.Devices",
                c => new
                    {
                        DeviceId = c.Int(nullable: false, identity: true),
                        DeviceCode = c.String(nullable: false, maxLength: 20, unicode: false),
                        DeviceName = c.String(nullable: false, maxLength: 30, unicode: false),
                        DeviceCategoryId = c.Int(nullable: false),
                        DeviceSpecId = c.Int(nullable: false),
                        DeviceUnitId = c.Int(nullable: false),
                        DeviceStatus = c.Int(nullable: false),
                        RegisterId = c.Int(nullable: false),
                        RegisterTime = c.DateTime(nullable: false),
                        Remark = c.String(maxLength: 150, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.DeviceId)
                .Index(t => t.DeviceCode, unique: true)
                .Index(t => t.DeviceName, unique: true);
            
            CreateTable(
                "dbo.DeviceSpecs",
                c => new
                    {
                        DeviceSpecId = c.Int(nullable: false, identity: true),
                        DeviceSpecName = c.String(nullable: false, maxLength: 30, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.DeviceSpecId)
                .Index(t => t.DeviceSpecName, unique: true);
            
            CreateTable(
                "dbo.MaterialReceiveDetails",
                c => new
                    {
                        MaterialReceiveDetailId = c.Int(nullable: false, identity: true),
                        MaterialReceiveId = c.Int(nullable: false),
                        ProductionPlanDetailId = c.Int(nullable: false),
                        StoreId = c.Int(nullable: false),
                        ReceiveCount = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.MaterialReceiveDetailId);
            
            CreateTable(
                "dbo.MaterialReceives",
                c => new
                    {
                        MaterialReceiveId = c.Int(nullable: false, identity: true),
                        ProductionPlanId = c.String(nullable: false, maxLength: 20, unicode: false),
                        ReceiveId = c.Int(nullable: false),
                        ReceiveDate = c.DateTime(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.MaterialReceiveId);
            
            CreateTable(
                "dbo.ProductCategories",
                c => new
                    {
                        ProductCategoryId = c.Int(nullable: false, identity: true),
                        ProductCategoryName = c.String(nullable: false, maxLength: 30, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductCategoryId)
                .Index(t => t.ProductCategoryName, unique: true);
            
            CreateTable(
                "dbo.ProductionLineCategories",
                c => new
                    {
                        ProductionLineCategorieId = c.Int(nullable: false, identity: true),
                        ProductionLineCategorieName = c.String(nullable: false, maxLength: 30, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductionLineCategorieId)
                .Index(t => t.ProductionLineCategorieName, unique: true);
            
            CreateTable(
                "dbo.ProductionLines",
                c => new
                    {
                        ProductionLineId = c.Int(nullable: false, identity: true),
                        ProductionLineName = c.String(nullable: false, maxLength: 30, unicode: false),
                        ProductionLineCaregoryId = c.Int(nullable: false),
                        ProductionTechnologyId = c.Int(nullable: false),
                        WorkShopId = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductionLineId);
            
            CreateTable(
                "dbo.ProductionPlanDetails",
                c => new
                    {
                        ProductionPlanDetailId = c.Int(nullable: false, identity: true),
                        ProductionPlanId = c.Int(nullable: false),
                        MaterialId = c.Int(nullable: false),
                        MaterialCount = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductionPlanDetailId);
            
            CreateTable(
                "dbo.ProductionPlans",
                c => new
                    {
                        ProductionPlanId = c.Int(nullable: false, identity: true),
                        ProductionPlanCode = c.String(nullable: false, maxLength: 20, unicode: false),
                        ProductionDate = c.DateTime(nullable: false),
                        DeliveryDate = c.DateTime(nullable: false),
                        ProductId = c.String(nullable: false, maxLength: 20, unicode: false),
                        TeamId = c.Int(nullable: false),
                        ProductionLineId = c.Int(nullable: false),
                        ProductionTechnologyId = c.Int(nullable: false),
                        OrderCount = c.Int(nullable: false),
                        OrderCode = c.String(nullable: false, maxLength: 20, unicode: false),
                        CustomerName = c.Int(nullable: false),
                        Priority = c.Int(nullable: false),
                        ProductionPlanStatus = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductionPlanId);
            
            CreateTable(
                "dbo.ProductionProcesses",
                c => new
                    {
                        ProductionProcessId = c.Int(nullable: false, identity: true),
                        ProductionProcessCode = c.String(nullable: false, maxLength: 20, unicode: false),
                        ProductionProcessName = c.String(nullable: false, maxLength: 30, unicode: false),
                        ProcessRequirements = c.String(nullable: false, maxLength: 200, unicode: false),
                        Remark = c.String(maxLength: 150, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductionProcessId)
                .Index(t => t.ProductionProcessCode, unique: true)
                .Index(t => t.ProductionProcessName, unique: true);
            
            CreateTable(
                "dbo.ProductionTechnologies",
                c => new
                    {
                        ProductionTechnologyId = c.Int(nullable: false, identity: true),
                        ProductionTechnologyCode = c.String(nullable: false, maxLength: 20, unicode: false),
                        ProductionTechnologyName = c.String(nullable: false, maxLength: 30, unicode: false),
                        GenerationDate = c.DateTime(nullable: false),
                        ProductId = c.Int(nullable: false),
                        MaterialId = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductionTechnologyId)
                .Index(t => t.ProductionTechnologyCode, unique: true)
                .Index(t => t.ProductionTechnologyName, unique: true);
            
            CreateTable(
                "dbo.ProductionTechnologyDetails",
                c => new
                    {
                        ProductionTechnologyDetailId = c.Int(nullable: false, identity: true),
                        ProductionTechnologyId = c.Int(nullable: false),
                        ProductionProcessId = c.String(nullable: false, maxLength: 20, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductionTechnologyDetailId);
            
            CreateTable(
                "dbo.Products",
                c => new
                    {
                        ProductId = c.Int(nullable: false, identity: true),
                        ProductCode = c.String(nullable: false, maxLength: 20, unicode: false),
                        ProductName = c.String(nullable: false, maxLength: 80, unicode: false),
                        MaintainerId = c.Int(nullable: false),
                        MaintenanceTime = c.DateTime(nullable: false),
                        ProductCategotyId = c.Int(nullable: false),
                        ProductSpecId = c.Int(nullable: false),
                        ProductUnitId = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductId)
                .Index(t => t.ProductCode, unique: true)
                .Index(t => t.ProductName, unique: true);
            
            CreateTable(
                "dbo.ProductSpecs",
                c => new
                    {
                        ProductSpecId = c.Int(nullable: false, identity: true),
                        ProductSpecName = c.String(nullable: false, maxLength: 30, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.ProductSpecId)
                .Index(t => t.ProductSpecName, unique: true);
            
            CreateTable(
                "dbo.StoreCategories",
                c => new
                    {
                        StoreCategorieId = c.Int(nullable: false, identity: true),
                        StoreCategorieName = c.String(nullable: false, maxLength: 30, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.StoreCategorieId)
                .Index(t => t.StoreCategorieName, unique: true);
            
            CreateTable(
                "dbo.Stores",
                c => new
                    {
                        StoreId = c.Int(nullable: false, identity: true),
                        StoreCode = c.String(nullable: false, maxLength: 20, unicode: false),
                        StoreName = c.String(nullable: false, maxLength: 30, unicode: false),
                        Storekeeper = c.Int(nullable: false),
                        StoreAddress = c.String(nullable: false, maxLength: 100, unicode: false),
                        StoreCategoryId = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.StoreId)
                .Index(t => t.StoreCode, unique: true)
                .Index(t => t.StoreName, unique: true);
            
            CreateTable(
                "dbo.TeamMembers",
                c => new
                    {
                        TeamMemberId = c.Int(nullable: false, identity: true),
                        TeamId = c.Int(nullable: false),
                        MemberId = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.TeamMemberId);
            
            CreateTable(
                "dbo.Teams",
                c => new
                    {
                        TeamId = c.Int(nullable: false, identity: true),
                        TeamName = c.String(nullable: false, maxLength: 30, unicode: false),
                        TeamContact = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.TeamId)
                .Index(t => t.TeamName, unique: true);
            
            CreateTable(
                "dbo.Units",
                c => new
                    {
                        UnitId = c.Int(nullable: false, identity: true),
                        UnitName = c.String(nullable: false, maxLength: 30, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.UnitId)
                .Index(t => t.UnitName, unique: true);
            
            CreateTable(
                "dbo.WorkShopCategories",
                c => new
                    {
                        WorkShopCategoryId = c.Int(nullable: false, identity: true),
                        WorkShopCategoryName = c.String(nullable: false, maxLength: 30, unicode: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.WorkShopCategoryId)
                .Index(t => t.WorkShopCategoryName, unique: true);
            
            CreateTable(
                "dbo.WorkShops",
                c => new
                    {
                        WorkShopId = c.Int(nullable: false, identity: true),
                        WorkShopName = c.String(nullable: false, maxLength: 30, unicode: false),
                        WorkShopContactId = c.Int(nullable: false),
                        WorkShopCategotyId = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        CreateUserId = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        LastUpdateUserId = c.Int(),
                        LastUpdateTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.WorkShopId)
                .Index(t => t.WorkShopName, unique: true);
            
            CreateIndex("dbo.Users", "UserName", unique: true);
            CreateIndex("dbo.Users", "Phone", unique: true);
        }
        
        public override void Down()
        {
            DropIndex("dbo.WorkShops", new[] { "WorkShopName" });
            DropIndex("dbo.WorkShopCategories", new[] { "WorkShopCategoryName" });
            DropIndex("dbo.Users", new[] { "Phone" });
            DropIndex("dbo.Users", new[] { "UserName" });
            DropIndex("dbo.Units", new[] { "UnitName" });
            DropIndex("dbo.Teams", new[] { "TeamName" });
            DropIndex("dbo.Stores", new[] { "StoreName" });
            DropIndex("dbo.Stores", new[] { "StoreCode" });
            DropIndex("dbo.StoreCategories", new[] { "StoreCategorieName" });
            DropIndex("dbo.ProductSpecs", new[] { "ProductSpecName" });
            DropIndex("dbo.Products", new[] { "ProductName" });
            DropIndex("dbo.Products", new[] { "ProductCode" });
            DropIndex("dbo.ProductionTechnologies", new[] { "ProductionTechnologyName" });
            DropIndex("dbo.ProductionTechnologies", new[] { "ProductionTechnologyCode" });
            DropIndex("dbo.ProductionProcesses", new[] { "ProductionProcessName" });
            DropIndex("dbo.ProductionProcesses", new[] { "ProductionProcessCode" });
            DropIndex("dbo.ProductionLineCategories", new[] { "ProductionLineCategorieName" });
            DropIndex("dbo.ProductCategories", new[] { "ProductCategoryName" });
            DropIndex("dbo.DeviceSpecs", new[] { "DeviceSpecName" });
            DropIndex("dbo.Devices", new[] { "DeviceName" });
            DropIndex("dbo.Devices", new[] { "DeviceCode" });
            DropIndex("dbo.DeviceCategories", new[] { "DeviceCategoryName" });
            DropTable("dbo.WorkShops");
            DropTable("dbo.WorkShopCategories");
            DropTable("dbo.Units");
            DropTable("dbo.Teams");
            DropTable("dbo.TeamMembers");
            DropTable("dbo.Stores");
            DropTable("dbo.StoreCategories");
            DropTable("dbo.ProductSpecs");
            DropTable("dbo.Products");
            DropTable("dbo.ProductionTechnologyDetails");
            DropTable("dbo.ProductionTechnologies");
            DropTable("dbo.ProductionProcesses");
            DropTable("dbo.ProductionPlans");
            DropTable("dbo.ProductionPlanDetails");
            DropTable("dbo.ProductionLines");
            DropTable("dbo.ProductionLineCategories");
            DropTable("dbo.ProductCategories");
            DropTable("dbo.MaterialReceives");
            DropTable("dbo.MaterialReceiveDetails");
            DropTable("dbo.DeviceSpecs");
            DropTable("dbo.Devices");
            DropTable("dbo.DeviceMaintenances");
            DropTable("dbo.DeviceInspections");
            DropTable("dbo.DeviceCategories");
        }
    }
}
